package io.github.xxyopen.novel.app.utils;



import io.github.xxyopen.novel.app.constant.MessageTypeConst;
import io.github.xxyopen.novel.core.auth.UserHolder;
import io.github.xxyopen.novel.dao.entity.AiChatMemory;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;

public class MessageConvertUtil {


    public static AiChatMemory toAiChatMemory(Message message, String conversationId,Long userId){
        AiChatMemory aiChatMemory = new AiChatMemory();

        aiChatMemory.setType(message.getMessageType().getValue());
        aiChatMemory.setContent(message.getText());
        aiChatMemory.setUserId(userId);
        aiChatMemory.setConversationId(conversationId);
        return aiChatMemory;
    }

    public static Message toMessage(AiChatMemory aiChatMemory){
        switch (aiChatMemory.getType()){
            case MessageTypeConst.USER  : return  new UserMessage(aiChatMemory.getContent());
            case MessageTypeConst.SYSTEM: return new SystemMessage(aiChatMemory.getContent());
            case MessageTypeConst.ASSISTANT: return new AssistantMessage(aiChatMemory.getContent());
            default: return null;
        }
    }
}
